package com.demo.controller;

import com.demo.constants.StatusCode;

import java.util.HashMap;
import java.util.Map;

public class BaseController {

	//	响应成功
	public Object success(String msg, Object data){
		return result(StatusCode.RESPONSE_SUCCESS, msg, data);
	}
	public Object success(String msg){
		return result(StatusCode.RESPONSE_SUCCESS, msg, null);
	}

	//	响应失败
	public Object fail(String msg, Object data){
		return result(StatusCode.RESPONSE_FAIL, msg, data);
	}
	public Object fail(String msg){
		return result(StatusCode.RESPONSE_FAIL, msg, null);
	}

	//	返回结果
	public Map result(Object code, String msg, Object data){
		return new HashMap(){{
			put("code", code);
			put("msg", msg);
			put("data", data );
		}};
	}

}
